package com.qifan.energy.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.qifan.energy.bean.entity.OrderAllMultiItemEntity;
import com.qifan.energy.R;
import com.qifan.energy.bean.result.OrderItem;
import com.qifan.energy.global.GlideApp;
import com.qifan.energy.util.CheckUtil;

import java.util.List;

public class OrderAllAdapter extends BaseMultiItemQuickAdapter<OrderAllMultiItemEntity,BaseViewHolder> {

    public OrderAllAdapter(@Nullable List<OrderAllMultiItemEntity> data) {
        super(data);
        addItemType(OrderAllMultiItemEntity.ALL, R.layout.order_tradesuccess_item);
        addItemType(OrderAllMultiItemEntity.DAIFU, R.layout.order_readypay_item);
        addItemType(OrderAllMultiItemEntity.DAIFA, R.layout.order_readyship_item);
        addItemType(OrderAllMultiItemEntity.DAISHOU, R.layout.order_readyreceive_item);
        addItemType(OrderAllMultiItemEntity.CLOSE, R.layout.order_tradefailure_item);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, OrderAllMultiItemEntity entity) {
        OrderItem item = entity.getOrderItem();
        switch (helper.getItemViewType()) {
            case OrderAllMultiItemEntity.ALL:
                if (CheckUtil.hasContent(item.getOrderItemList())) {
                    OrderItem.OrderItemListBean orderItemListBean = item.getOrderItemList().get(0);
                    int totalCount = 0;
                    for (OrderItem.OrderItemListBean itemListBean : item.getOrderItemList()) {
                        totalCount += itemListBean.getProductQuantity();
                    }
                    helper.addOnClickListener(R.id.view_ship_tv)
                            .addOnClickListener(R.id.confirm_delete_tv);
                    helper.setText(R.id.product_name_tv,orderItemListBean.getProductName())
                            .setText(R.id.price_tv,String.format("￥%.02f",orderItemListBean.getRealAmount()))
                            .setText(R.id.qulity_tv,String.format("x%d",orderItemListBean.getProductQuantity()))
                            .setText(R.id.product_qulity_tv,String.format("共%d件商品 总计:",totalCount))
                            .setText(R.id.real_amount_tv,String.format("￥%.02f",item.getTotalAmount()))
                            .setText(R.id.game_zeng_tv,String.format("游戏分%d",orderItemListBean.getGiftIntegration()))
                            .setText(R.id.game_zeng_tv,String.format("时间卡%.02f",orderItemListBean.getGiftTimeCard()))
                            .setText(R.id.coupon_zeng_tv,String.format("优惠券%.02f",orderItemListBean.getGiftCouponAmount()));
                    ImageView productIv = helper.getView(R.id.product_iv);
                    GlideApp.with(helper.itemView)
                            .load(orderItemListBean.getProductPic())
                            .placeholder(R.mipmap.icon_default_rect)
                            .error(R.mipmap.icon_default_rect)
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                            .into(productIv);
                }
                break;
            case OrderAllMultiItemEntity.DAIFU:
                if (CheckUtil.hasContent(item.getOrderItemList())) {
                    OrderItem.OrderItemListBean orderItemListBean = item.getOrderItemList().get(0);
                    int totalCount = 0;
                    for (OrderItem.OrderItemListBean itemListBean : item.getOrderItemList()) {
                        totalCount += itemListBean.getProductQuantity();
                    }
                    helper.addOnClickListener(R.id.cancel_order_tv)
                            .addOnClickListener(R.id.pay_order_tv);
                    helper.setText(R.id.product_name_tv,orderItemListBean.getProductName())
                            .setText(R.id.price_tv,String.format("￥%.02f",orderItemListBean.getRealAmount()))
                            .setText(R.id.qulity_tv,String.format("x%d",orderItemListBean.getProductQuantity()))
                            .setText(R.id.product_qulity_tv,String.format("共%d件商品 总计:",totalCount))
                            .setText(R.id.real_amount_tv,String.format("￥%.02f",item.getTotalAmount()))
                            .setText(R.id.game_zeng_tv,String.format("游戏分%d",orderItemListBean.getGiftIntegration()))
                            .setText(R.id.game_zeng_tv,String.format("时间卡%.02f",orderItemListBean.getGiftTimeCard()))
                            .setText(R.id.coupon_zeng_tv,String.format("优惠券%.02f",orderItemListBean.getGiftCouponAmount()));
                    ImageView productIv = helper.getView(R.id.product_iv);
                    GlideApp.with(helper.itemView)
                            .load(orderItemListBean.getProductPic())
                            .placeholder(R.mipmap.icon_default_rect)
                            .error(R.mipmap.icon_default_rect)
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                            .into(productIv);
                }
                break;
            case OrderAllMultiItemEntity.DAIFA:
                if (CheckUtil.hasContent(item.getOrderItemList())) {
                    OrderItem.OrderItemListBean orderItemListBean = item.getOrderItemList().get(0);
                    int totalCount = 0;
                    for (OrderItem.OrderItemListBean itemListBean : item.getOrderItemList()) {
                        totalCount += itemListBean.getProductQuantity();
                    }
                    helper.setText(R.id.product_name_tv,orderItemListBean.getProductName())
                            .setText(R.id.price_tv,String.format("￥%.02f",orderItemListBean.getRealAmount()))
                            .setText(R.id.qulity_tv,String.format("x%d",orderItemListBean.getProductQuantity()))
                            .setText(R.id.product_qulity_tv,String.format("共%d件商品 总计:",totalCount))
                            .setText(R.id.real_amount_tv,String.format("￥%.02f",item.getTotalAmount()))
                            .setText(R.id.game_zeng_tv,String.format("游戏分%d",orderItemListBean.getGiftIntegration()))
                            .setText(R.id.game_zeng_tv,String.format("时间卡%.02f",orderItemListBean.getGiftTimeCard()))
                            .setText(R.id.coupon_zeng_tv,String.format("优惠券%.02f",orderItemListBean.getGiftCouponAmount()));
                    ImageView productIv = helper.getView(R.id.product_iv);
                    GlideApp.with(helper.itemView)
                            .load(orderItemListBean.getProductPic())
                            .placeholder(R.mipmap.icon_default_rect)
                            .error(R.mipmap.icon_default_rect)
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                            .into(productIv);
                }
                break;
            case OrderAllMultiItemEntity.DAISHOU:
                if (CheckUtil.hasContent(item.getOrderItemList())) {
                    OrderItem.OrderItemListBean orderItemListBean = item.getOrderItemList().get(0);
                    int totalCount = 0;
                    for (OrderItem.OrderItemListBean itemListBean : item.getOrderItemList()) {
                        totalCount += itemListBean.getProductQuantity();
                    }
                    helper.addOnClickListener(R.id.view_ship_tv)
                            .addOnClickListener(R.id.confirm_receive_tv);
                    helper.setText(R.id.product_name_tv,orderItemListBean.getProductName())
                            .setText(R.id.price_tv,String.format("￥%.02f",orderItemListBean.getRealAmount()))
                            .setText(R.id.qulity_tv,String.format("x%d",orderItemListBean.getProductQuantity()))
                            .setText(R.id.product_qulity_tv,String.format("共%d件商品 总计:",totalCount))
                            .setText(R.id.real_amount_tv,String.format("￥%.02f",item.getTotalAmount()))
                            .setText(R.id.game_zeng_tv,String.format("游戏分%d",orderItemListBean.getGiftIntegration()))
                            .setText(R.id.game_zeng_tv,String.format("时间卡%.02f",orderItemListBean.getGiftTimeCard()))
                            .setText(R.id.coupon_zeng_tv,String.format("优惠券%.02f",orderItemListBean.getGiftCouponAmount()));
                    ImageView productIv = helper.getView(R.id.product_iv);
                    GlideApp.with(helper.itemView)
                            .load(orderItemListBean.getProductPic())
                            .placeholder(R.mipmap.icon_default_rect)
                            .error(R.mipmap.icon_default_rect)
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                            .into(productIv);
                }
                break;
            case OrderAllMultiItemEntity.CLOSE:
                if (CheckUtil.hasContent(item.getOrderItemList())) {
                    OrderItem.OrderItemListBean orderItemListBean = item.getOrderItemList().get(0);
                    int totalCount = 0;
                    for (OrderItem.OrderItemListBean itemListBean : item.getOrderItemList()) {
                        totalCount += itemListBean.getProductQuantity();
                    }
                    helper.setText(R.id.product_name_tv,orderItemListBean.getProductName())
                            .setText(R.id.price_tv,String.format("￥%.02f",orderItemListBean.getRealAmount()))
                            .setText(R.id.qulity_tv,String.format("x%d",orderItemListBean.getProductQuantity()))
                            .setText(R.id.product_qulity_tv,String.format("共%d件商品 总计:",totalCount))
                            .setText(R.id.real_amount_tv,String.format("￥%.02f",item.getTotalAmount()))
                            .setText(R.id.game_zeng_tv,String.format("游戏分%d",orderItemListBean.getGiftIntegration()))
                            .setText(R.id.game_zeng_tv,String.format("时间卡%.02f",orderItemListBean.getGiftTimeCard()))
                            .setText(R.id.coupon_zeng_tv,String.format("优惠券%.02f",orderItemListBean.getGiftCouponAmount()));
                    ImageView productIv = helper.getView(R.id.product_iv);
                    GlideApp.with(helper.itemView)
                            .load(orderItemListBean.getProductPic())
                            .placeholder(R.mipmap.icon_default_rect)
                            .error(R.mipmap.icon_default_rect)
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                            .into(productIv);
                }
                break;
        }
    }
}
